﻿using System;

namespace SsisLdapSource
{
    using System.DirectoryServices.Protocols;

    using global::SsisLdapSource.DirectoryServicesProtocolsExtensions;

    public partial class SsisLdapSource : ILdapConnectionPropertiesContainer
    {
        public string HostOrDomainName
        {
            get
            {
                return (string)ComponentMetaData.CustomPropertyCollection["HostOrDomainName"].Value;
            }
            set { throw new NotImplementedException(); }
        }

        public int LdapHostPortNumber
        {
            get
            {
                return (int)ComponentMetaData.CustomPropertyCollection["PortNumber"].Value;
            }
            set { throw new NotImplementedException(); }
        }

        public string ConnectionAccountName
        {
            get
            {
                return (string)ComponentMetaData.CustomPropertyCollection["ConnectionAccountName"].Value;
            }
            set { throw new NotImplementedException(); }
        }

        public string ConnectionAccountPassword
        {
            get
            {
                return (string)ComponentMetaData.CustomPropertyCollection["ConnectionAccountPassword"].Value;
            }
            set { throw new NotImplementedException(); }
        }

        public bool UseProcessSecurityContextFlag
        {
            get
            {
                return (bool)ComponentMetaData.CustomPropertyCollection["UseTaskSecurityContext"].Value;
            }

            set { throw new NotImplementedException(); }
        }

        public bool UseSSLFlag
        {
            get
            {
                return (bool)ComponentMetaData.CustomPropertyCollection["UseSSL"].Value;
            }
        }

        public AuthType AuthType
        {
            get
            {
                switch (ComponentMetaData.CustomPropertyCollection["AuthenticationType"].Value.ToString().ToUpper())
                {
                    case "NEGOTIATE":
                        return AuthType.Negotiate;
                    case "BASIC":
                        return AuthType.Basic;
                    default:
                        throw new Exception(
                            string.Format("Unsupported authentication type was provided {0}", ComponentMetaData.CustomPropertyCollection["AuthenticationType"].Value));
                }
            }
            set { throw new NotImplementedException(); }
        }

        private LdapConnection LdapConnection
        {
            get
            {
                var ldapConnectionFactory = new LdapConnectionFactory(this);
                return ldapConnectionFactory.Create();
            }
        }
    }
}
